//https://leetcode.cn/problems/longest-increasing-subsequence/
class Solution {
    //记忆化搜索
    int n;
    public int lengthOfLIS(int[] nums) {
        int ret = 0;
        n = nums.length;
        int[] memo = new int[n];
        for(int i = 0; i < n; i++) {
            ret = Math.max(ret, dfs(nums, i, memo));
        }
        return ret;
    }
    public int dfs(int[] nums, int pos, int[] memo) {
        if(memo[pos] != 0) return memo[pos];
        int ret = 1;
        for(int i = pos + 1; i < n; i++) {
            if(nums[i] > nums[pos]) {
                ret = Math.max(ret,  dfs(nums, i, memo) + 1);
            }
        }
        memo[pos] = ret;
        return ret;
    }
}